package com.example.wechat.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.wechat.R;
import com.example.wechat.adapter.FavoritesChatAdapter;
import com.example.wechat.model.FavoriteChat;
import java.util.ArrayList;
import java.util.List;

public class FavoritesChatFragment extends Fragment {
    private RecyclerView recyclerView;
    private FavoritesChatAdapter adapter;
    private List<FavoriteChat> favoriteChats;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_favorites_chat, container, false);
        
        recyclerView = view.findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        
        favoriteChats = new ArrayList<>();
        adapter = new FavoritesChatAdapter(favoriteChats);
        recyclerView.setAdapter(adapter);
        
        loadFavoriteChats();
        
        return view;
    }

    private void loadFavoriteChats() {
        // TODO: 从数据库或服务器加载收藏的聊天记录
        // 这里添加一些测试数据
        favoriteChats.add(new FavoriteChat("张三", "你好，这是一条收藏的聊天记录", System.currentTimeMillis()));
        favoriteChats.add(new FavoriteChat("李四", "明天见！", System.currentTimeMillis() - 86400000));
        adapter.notifyDataSetChanged();
    }
} 